package com.cennavi.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cennavi.service.CommonService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by lixiaoshuang on 2018/10/16.
 */
@Controller
//@RequestMapping("/common")
public class CommonController {
    @Autowired
    CommonService commonService;

    /**
     * 查询表的列名（支持多个表）
     * @param tablename 表名，支持多个表，逗号隔开
     * @return
     */
    @RequestMapping("/columnsToShow")
    @ResponseBody
    public  Object getColumnsToShow(@RequestParam(value="tablename")String tablename){
        return commonService.getColumnsToShow(tablename);
    }

    @RequestMapping("/getTableInfo")
    @ResponseBody
    public JSONArray getTableInfo(){
        JSONArray jsonArray = new JSONArray();
        List list = commonService.getTableNames();
        jsonArray.addAll(list);
        return  jsonArray;
    }

    @RequestMapping("/getScore")
    public @ResponseBody Object getScore(@Param("tablesname")String tablename){

        return commonService.getScore(null);
    }
    @RequestMapping("/hello")
    public String getColumnsToShow(){
        return "login";
    }
}
